package at.fhooe.im440.pandora.hud;

import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;

import at.fhooe.im440.pandora.core.Core;
import at.fhooe.im440.pandora.time.Time;
import at.fhooe.im440.pandora.enumeration.Enumerations.ClockType;

public class Clock extends HUD {

	private int r;
	private float x;
	private float y;
	private double thetaSeconds;
	private double thetaMinutes;
	private Time time;
	
	private ClockType type;
	
	public Clock(String name, Core core, Time time, float x, float y, int r, ClockType type) {
		super(name, core);
		this.x=x;
		this.y=y;
		this.r = r;
		thetaSeconds = 0;
		thetaMinutes = 0;
		this.time = time;
		this.type = type;
	}

	@Override
	public void update() {
		
		long timeInSeconds = 0;
		long timeInMinutes = 0;
		
		switch (type) 
		{
		case GAMECLOCK:
			timeInSeconds = (long)((time.getTotalGameTime()/1000)%60);
			timeInMinutes = (long)((time.getTotalGameTime()/1000/60)%60);
			break;
		case PAUSECLOCK:
			timeInSeconds = (long)((time.getTotalPauseTime()/1000)%60);
			timeInMinutes = (long)((time.getTotalPauseTime()/1000/60)%60);
			break;
		}
		thetaSeconds= Math.toRadians((timeInSeconds%60)*6);
		thetaMinutes = Math.toRadians((timeInMinutes%60)*6);
	}

	@Override
	public Point2D getPosition() {
		return new Point2D.Float(x,y);
	}

	@Override
	public void setPosition(float x, float y) {
	}

	@Override
	public void render(Graphics2D g) {
		g.setColor(Color.black);
		g.drawOval((int)x,(int) y, 2*r, 2*r);
		g.setColor(Color.red);
		g.rotate(-thetaSeconds, (int)x+r,(int)y+r);
		g.drawLine((int)x+r, (int)y+r, (int)x+r, (int)y+2*r);
		g.rotate(thetaSeconds,(int)x+r,(int)y+r);
		g.setColor(Color.blue);
		g.rotate(-thetaMinutes, (int)x+r,(int)y+r);
		g.drawLine((int)x+r, (int)y+r, (int)x+r, (int)y+2*r);
		g.rotate(thetaMinutes, (int)x+r,(int)y+r);
		
	}
}
